﻿<UserControl xmlns:my="clr-namespace:System.Windows.Controls.WpfPropertyGrid;assembly=System.Windows.Controls.WpfPropertyGrid"  x:Class="devtm.Editor.Configuration.LstBox"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             xmlns:c="clr-namespace:devtm.Editor.Configuration.Data"
             xmlns:f="clr-namespace:devtm.Editor.Configuration.Data.SimpleTemplates"
             d:DesignHeight="300" d:DesignWidth="300">
    
<UserControl.Resources>

        <DataTemplate DataType="{x:Type c:TemplateDefault}">
            <Grid HorizontalAlignment="Stretch">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Label Grid.Row="0" Content="{Binding Name}" FontWeight="Bold" MinWidth="300"  HorizontalAlignment="Left" />
                <Label Grid.Row="1" Content="{Binding Type}" ToolTip="{Binding Value}" MinWidth="300" />
            </Grid>
        </DataTemplate>
        
        <DataTemplate DataType="{x:Type c:ConfigPropertyCollection}">
            <DataGrid x:Name="grid" ItemsSource="{Binding Value}" MinHeight="0" Margin="30,20,0,5" Visibility="Collapsed" HorizontalAlignment="Stretch" />
        </DataTemplate>    
    
        <DataTemplate DataType="{x:Type c:TemplateTimeSpan}">
            <TextBox 
                Text="{Binding Value}" 
                Tag="{Binding .}"
                TextChanged="Validator" 
                IsEnabled="{Binding CanWrite}"  />
        </DataTemplate>

        <DataTemplate DataType="{x:Type c:TemplateEnum}">
            <ComboBox 
                SelectedItem="{Binding Value}" 
                ItemsSource="{Binding Tag}" 
                IsEnabled="{Binding CanWrite}"
                />
        </DataTemplate>
    
        <DataTemplate DataType="{x:Type c:TemplateString}">
            <TextBox
                HorizontalAlignment="Stretch"
                Text="{Binding Value }" 
                Tag="{Binding .}" 
                TextChanged="Validator" 
                IsEnabled="{Binding CanWrite}" />
        </DataTemplate>

        <DataTemplate DataType="{x:Type c:TemplateInteger}">
            <TextBox
                Text="{Binding Value}" 
                Tag="{Binding .}" 
                TextChanged="Validator" 
                IsEnabled="{Binding CanWrite}" />
        </DataTemplate>

        <DataTemplate DataType="{x:Type c:TemplateDateTime}">
            <TextBox
                Text="{Binding Value}" 
                Tag="{Binding .}" 
                TextChanged="Validator" 
                IsEnabled="{Binding CanWrite}" />
        </DataTemplate>

        <DataTemplate DataType="{x:Type c:TemplateConnexionStringName}">
            <ComboBox 
                SelectedItem="{Binding Value}" 
                ItemsSource="{Binding Tag}" 
                IsEnabled="{Binding CanWrite}"  />
        </DataTemplate>

        <DataTemplate DataType="{x:Type c:TemplateVersion}">
            <TextBox
                Text="{Binding Value}" 
                Tag="{Binding .}" 
                TextChanged="Validator" 
                IsEnabled="{Binding CanWrite}"  />
        </DataTemplate>

        <DataTemplate DataType="{x:Type c:TemplateMethod}">
            <Grid HorizontalAlignment="Stretch">

                <Grid.ColumnDefinitions>
                    <ColumnDefinition MinWidth="70" Width="*" />
                    <ColumnDefinition Width="35" />
                </Grid.ColumnDefinitions>

                <Button Grid.Column="0" Content="{Binding Name}" Tag="{Binding .}" Click="RunEditor" />
            </Grid>
        </DataTemplate>

        <DataTemplate DataType="{x:Type c:TemplateUri}">
            <TextBox Grid.Column="0" 
                Text="{Binding Value}" 
                Tag="{Binding .}" 
                TextChanged="Validator" 
                IsEnabled="{Binding CanWrite}" />
        </DataTemplate>

        <DataTemplate DataType="{x:Type c:TemplateBool}">
            <CheckBox Grid.Row="1" IsChecked="{Binding Value}" IsEnabled="{Binding CanWrite}" />
        </DataTemplate>

        <DataTemplate DataType="{x:Type c:TemplateListeSelector}">
            <ComboBox
                Tag="{Binding .}"
                DisplayMemberPath="Property1"
                ItemsSource="{Binding Tag}" 
                IsEnabled="{Binding CanWrite}" 
                SelectedItem="{Binding Value}" 
                SelectionChanged="ComboBox_SelectionChanged"  />
        </DataTemplate>

        <DataTemplate DataType="{x:Type c:TemplateAttributeXml}">
            <TextBox Text="{Binding Value}" Tag="{Binding .}"
                     TextChanged="Validator" IsEnabled="{Binding CanWrite}" />
        </DataTemplate>

        <DataTemplate DataType="{x:Type c:TemplateHost}">
            <TextBox Text="{Binding LiteDisplay}"
                     ToolTip="{Binding ValueString}" 
                     Tag="{Binding .}" TextChanged="Validator" IsEnabled="{Binding CanWrite}" />
        </DataTemplate>

        <DataTemplate DataType="{x:Type c:TemplateType}">
            <StackPanel Orientation="Horizontal">
                <Button Content="Select" Click="RunEditor" Tag="{Binding .}" IsEnabled="{Binding CanWrite}" Margin="0,0,20,0" Width="70" />
                <TextBlock Text="{Binding LiteDisplay}" ToolTip="{Binding ValueString}" TextWrapping="WrapWithOverflow" />
            </StackPanel>
        </DataTemplate>


        <DataTemplate DataType="{x:Type f:StringSimpleProperty}">
            <TextBox
                HorizontalAlignment="Stretch"
                Text="{Binding Value }" 
                Tag="{Binding .}" />
        </DataTemplate>

        <DataTemplate DataType="{x:Type c:ItemPair}">
            <ContentPresenter Content="{Binding Value}" DockPanel.Dock="Left" />
        </DataTemplate>

    
        <DataTemplate DataType="{x:Type c:TemplateNameValueCollection}">
            <ItemsControl ItemsSource="{Binding Liste}" HorizontalAlignment="Stretch" DataContext="{Binding .}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Vertical" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Vertical" HorizontalAlignment="Stretch" Margin="5,7">
                            <Label Content="{Binding Key}"
                               FontWeight="Bold" 
                               ToolTip="{Binding ViewDescription}"
                               HorizontalAlignment="Left" />
                            <DockPanel LastChildFill="True" Margin="15,0">
                                <ContentPresenter Content="{Binding .}" DockPanel.Dock="Left" />
                            </DockPanel>
                        </StackPanel>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </DataTemplate>

    
    </UserControl.Resources>
    
    <Grid>
        <ScrollViewer>
            <ItemsControl ItemsSource="{Binding .}" x:Name="ListeBase" HorizontalAlignment="Stretch" >
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Vertical" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                    <StackPanel Orientation="Vertical" Margin="20,25,70,10" HorizontalAlignment="Stretch">
                        <Label Content="{Binding Name}"
                               FontWeight="Bold" 
                               ToolTip="{Binding ViewDescription}"
                               HorizontalAlignment="Left" />
                        <DockPanel LastChildFill="True" Margin="15,0">
                            <Image DockPanel.Dock="Right"
                                   Source="/devtm.Editor.Configuration;component/Images/erreur.png" 
                                   Width="24" 
                                   Height="24" 
                                   Visibility="{Binding VisibleError}"
                                   Margin="15,0,0,0"/>
                                <ContentPresenter Content="{Binding .}" DockPanel.Dock="Left" />
                        </DockPanel>
                    </StackPanel>
                </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>
    </Grid>

</UserControl>
